﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 社团
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string username = textBox1.Text;
            string  password = textBox2.Text;
            string sqlconnect = "Server = DESKTOP-FP3F9RQ; DataBase=社团成员信息管理系统;User ID=sa;Password=1111;Trusted_Connection = False;";
            using (SqlConnection connection = new SqlConnection(sqlconnect))
            {
                
                    connection.Open();
                    string query = "SELECT * FROM [用户表] WHERE username = @username AND password = @password";
                    using (SqlCommand command = new SqlCommand(query, connection))
                    {
                        command.Parameters.AddWithValue("@username", username);
                        command.Parameters.AddWithValue("@password", password);
                        SqlDataReader reader = command.ExecuteReader();
                        if (reader.Read())
                        {
                            string userrole = reader["power"].ToString();
                            userrole = userrole.Replace(" ", "");
                        switch (userrole)
                            {
                                case "Admin":
                                    Form2 form2 = new Form2();
                                    form2.ShowDialog();
                                    break;
                                case "User":
                                    Form3 form3 = new Form3();
                                    form3.ShowDialog();
                                    break;
                                
                            }

                        }
                        else
                        {
                            MessageBox.Show("用户名或密码错误");
                        }
                        connection.Close();
                    }
                
            }


        }
    }
}
